package functional.stream;

import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;

import java.util.Arrays;
import java.util.List;

/**
 * @author lyx
 * @Date 2021/6/26 12:23
 * 要求
 * 1.一行代码
 * 2.id偶数
 * 3.年龄=>23
 * 4.用户名转大写
 * 5.用户名字母倒序
 * 6.只输出一个用户
 */
public class UserTest {
    public static void main(String[] args) {
        User user1 = new User(1,"a",20);
        User user2 = new User(2,"b",21);
        User user3 = new User(3,"c",22);
        User user4 = new User(4,"d",23);
        User user5 = new User(5,"e",24);
        User user6 = new User(6,"f",25);
        List<User> users = Arrays.asList(user1, user2, user3, user4, user5, user6);

        users.stream()
                .filter( u->{return u.getId()%2==0;} ) //Predicate函数式接口
                .filter( u->{return u.getAge()>=20;} )
                .map( u->{return u.getName().toUpperCase();} ) //Function函数式接口 ,String参数,返回也是String
                .sorted( (uu1,uu2)->{ return uu2.compareTo(uu1);} )//倒叙方法
                .limit(2)
                .forEach(System.out::println);//Consumer消费型接口,没有返回值的,遍历打印;
    }
}
